#include <bits/stdc++.h>
using namespace std;
map<string, string> guize;
map<string, int> step;
int main() {
  string A, B;
  cin >> A >> B;
  string a, b;
  while (cin >> a >> b) {
    guize[a] = b;
  }

  queue<string> Q;
  Q.push(A);
  step[A] = 0;

  while (!Q.empty()) {
    string head = Q.front();

    if (step[head] > 10) {
      cout << "NO ANSWER!";
      break;
    }

    if (head == B) {
      cout << step[B];
      break;
    }
    Q.pop();
    for (auto k : guize) {
      string a = k.first;
      string b = k.second;
      string t = head;
      int p = 0;
      while (true) {
        p = t.find(a,p);
        if (p == string::npos)
          break;
        t.replace(p, a.size(), b);
        if (step.count(t) == 0) {
          step[t] = step[head] + 1;
          Q.push(t);
        }
        p = p + b.size();
      }

    }
  }

  return 0;
}